package action

import (
	"MessageSendService/app/api/internal/mq"
	"MessageSendService/app/api/internal/process"
	"MessageSendService/app/common/enum/channalType"
	"MessageSendService/app/common/log"
	"context"
	"go.uber.org/zap"
)

type SendMQAction struct {
}

func (s SendMQAction) Process(ctx *process.ProcessContext) error {
	log.GetLogger().Info("发送消息到MQ", zap.Any("taskInfoList", ctx.ProcessModel.TaskInfo))
	for _, taskInfo := range ctx.ProcessModel.TaskInfo {
		log.GetLogger().Info("短信渠道", zap.Any("taskInfo", taskInfo))
		//短信渠道
		if taskInfo.SendChannel == channalType.Sms || taskInfo.SendChannel == channalType.Email {
			//封装消息，发送到MQ
			err := mq.SendMessage(context.Background(), taskInfo)
			if err != nil {
				return err
			}
		}
	}
	return nil
}

func NewSendMQAction() *SendMQAction {
	log.GetLogger().Info("发送消息到MQ")
	return &SendMQAction{}
}
